package 代码记录.指定公司代码练习记录.华为_2024.分值100;

import java.util.Scanner;

/**
 * @author zx
 * @create 2024-02-02 20:07
 * 力扣原题：不同路径II_63(二刷)
 */
public class 园区参观路径_27 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int m = sc.nextInt();
        int n = sc.nextInt();
        int[][] arr = new int[m][n];
        for(int i = 0;i < m;i++){
            for(int j = 0;j < n;j++){
                arr[i][j] = sc.nextInt();
            }
        }
        int[][] dp = new int[m][n];
        //一旦遇到obstacleGrid[i][0] == 1的情况就停止dp[i][0]的赋值1的操作
        for(int i = 0;i < m && arr[i][0] == 0;i++){
            dp[i][0] = 1;
        }
        for(int j = 0;j < n && arr[0][j] == 0;j++){
            dp[0][j] = 1;
        }
        for(int i = 1;i < m;i++){
            for(int j = 1;j < n;j++){
                if(arr[i][j] == 1){
                    continue;
                }else{
                    //            left              up
                    dp[i][j] = dp[i][j - 1] + dp[i - 1][j];
                }
            }
        }
        System.out.println(dp[m - 1][n - 1]);
    }
}
